﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.OleDb;

namespace CustSign
{
    public partial class frmLottery : Form
    {
        Int32 intState,intCardID,intCardNum;
        ArrayList PanGroup,PrizeGroup;        
        Random CardID;        

        public frmLottery()
        {
            InitializeComponent();
        }

        private void frmLottery_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (TCardScroll.Enabled == true)
                {
                    TCardScroll.Enabled = false;                    

                    if (intState == 0)
                    {
                        lblPrizeTCard1.Text = NewPrize();
                    }
                    else if (intState == 1)
                    {
                        lblPrizeTCard2.Text = NewPrize();
                    }
                    else if (intState == 2)
                    {
                        lblPrizeTCard3.Text = NewPrize();
                    }
                    else if (intState == 3)
                    {
                        lblPrizeSCard1.Text = NewPrize();
                    }
                    else if (intState == 4)
                    {
                        lblPrizeSCard2.Text = NewPrize();
                    }
                    else if (intState == 5)
                    {
                        lblPrizeFCard.Text = NewPrize();
                    }
                    else
                    {
                    }                    
                }
                else
                {
                    TCardScroll.Enabled = true;
                }
            }

            if (e.KeyChar == 27)
            {
                this.Dispose();
            }
        }

        private void frmLottery_Load(object sender, EventArgs e)
        {
            this.Top = 0;
            this.Left = 0;
            this.Width = Screen.GetWorkingArea(this).Width;
            this.Height = Screen.GetWorkingArea(this).Height;
            intState = 0;

            this.BackgroundImage = Properties.Resources.imageback;

            lblPrizeFCard.Text = "                ";
            lblPrizeSCard1.Text = "                ";
            lblPrizeSCard2.Text = "                ";
            lblPrizeTCard1.Text = "                ";
            lblPrizeTCard2.Text = "                ";
            lblPrizeTCard3.Text = "                ";
            
            lblPrizeF.Top = (Int32)Math.Ceiling(this.Height * 0.223);
            lblPrizeFCard.Top = (Int32)Math.Ceiling(this.Height * 0.223);

            lblPrizeS.Top = (Int32)Math.Ceiling(this.Height * 0.323);
            lblPrizeSCard1.Top = (Int32)Math.Ceiling(this.Height * 0.323); 
            lblPrizeSCard2.Top = (Int32)Math.Ceiling(this.Height * 0.423);

            lblPrizeT.Top = (Int32)Math.Ceiling(this.Height * 0.523);
            lblPrizeTCard1.Top = (Int32)Math.Ceiling(this.Height * 0.523);
            lblPrizeTCard2.Top = (Int32)Math.Ceiling(this.Height * 0.623);
            lblPrizeTCard3.Top = (Int32)Math.Ceiling(this.Height * 0.723);

            lblCardScroll.Top = (Int32)Math.Ceiling(this.Height * 0.823);

            lblPrizeF.Left = (Int32)(this.Width - lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblPrizeFCard.Left = (Int32)(this.Width + lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblPrizeS.Left = (Int32)(this.Width - lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblPrizeSCard1.Left = (Int32)(this.Width + lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblPrizeSCard2.Left = (Int32)(this.Width + lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblPrizeT.Left = (Int32)(this.Width - lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblPrizeTCard1.Left = (Int32)(this.Width + lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblPrizeTCard2.Left = (Int32)(this.Width + lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblPrizeTCard3.Left = (Int32)(this.Width + lblPrizeF.Width - lblPrizeFCard.Width) / 2;
            lblCardScroll.Left = (Int32)(this.Width - lblPrizeFCard.Width) / 2; ;

            PanGroup = new ArrayList();
            PrizeGroup = new ArrayList();

            OleDbConnection Conn = new OleDbConnection(Properties.Settings.Default.strConn);

            OleDbCommand Comm = Conn.CreateCommand();
            OleDbDataReader CustRead;
            Conn.Open();

            Comm.CommandText = "SELECT distinct Pan FROM TSigns";
            CustRead = Comm.ExecuteReader();

            while (CustRead.Read())
            {
                PanGroup.Add(CustRead["Pan"]);
            }

            CustRead.Close();

            CustRead.Dispose();
            Comm.Dispose();
            Conn.Close();
            Conn.Dispose();

            intCardID = 0;
            intCardNum = PanGroup.Count;

            CardID = new Random();

            TCardScroll.Enabled = false;
        }        

        private void TCardScrollView(object sender, EventArgs e)
        {            
            lblCardScroll.Text = NewCard();
        }

        private String NewCard()
        {
            intCardID = CardID.Next(0, PanGroup.Count - 1);

            return (String)PanGroup[intCardID];
        }

        private String NewPrize()
        {
            String PrizeCard;
            PrizeCard = NewCard();
            PrizeGroup.Add(PrizeCard);
            PanGroup.Remove(PrizeCard);
            intState++;
            return PrizeCard;
        }
    }
}
 